package calculation;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author jzajaczek
 */
@ManagedBean(name="toolUnit")
@SessionScoped
public class ToolUnitBean implements Serializable {
    
    private static String[] unitKinds = {"SI", "Imperial"};
    
    private String selectedUnit;

    private List<String> availableUnits = new ArrayList<String>();
    
    // dimensions
    private double millimetre;
    
    public double convertMillimetreToInch(double millimetre){
        return millimetre * 2.54;
    };
    
    public double convertInchToMillimetre(double inch){
        return inch / 2.54;
    };
    
    public ToolUnitBean() {
        availableUnits.add("SI");
        availableUnits.add("Imperial");
    }

    /**
     * metoda zaokrąglania wyników
     * @param value 
     */
    public double round(double value, int precision) {
        double factor_ = (long)Math.pow(10, precision);
        value = value * factor_;
        long value_ = Math.round(value);
        return (double)value_ / factor_;
    }    
    /**
     * @return the millimetre
     */
    public double getMillimetre() {
        return millimetre;
    }

    /**
     * @param millimetre the millimetre to set
     */
    public void setMillimetre(double millimetre) {
        this.millimetre = millimetre;
    }

    /**
     * @return the selectedUnits
     */
    public String getSelectedUnit() {
        return selectedUnit;
    }

    /**
     * @param selectedUnits the selectedUnits to set
     */
    public void setSelectedUnit(String selectedUnit) {
        this.selectedUnit = selectedUnit;
    }

    /**
     * @return the availableUnits
     */
    public List<String> getAvailableUnits() {
        return availableUnits;
    }

    /**
     * @param availableUnits the availableUnits to set
     */
    public void setAvailableUnits(List<String> availableUnits) {
        this.availableUnits = availableUnits;
    }
}